//检索
function searchs(){
    top.jzts();
    $("#form").submit();
}

//详情
function detail(id) {
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title = "详情";
    diag.URL = path + '/admin/promotionFeeConfig/detailPage?id='+ id;
    diag.Width = 1050;
    diag.Height = 580;
    diag.CancelEvent = function(){ //关闭事件
        diag.close();
    };
    diag.show();
}

//新增
function add(currentPage){
    //var flag = validateAdd();
    //if (flag) {
        top.jzts();
        var diag = new top.Dialog();
        diag.Drag = true;
        diag.Title ="新增";
        diag.URL = path + '/admin/promotionFeeConfig/addPage';
        diag.Width = 1050;
        diag.Height = 580;
        diag.CancelEvent = function(){//关闭事件
            if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
                if(currentPage == '0'){
                    top.jzts();
                    setTimeout("self.location=self.location",100);
                }else{
                    nextPage(currentPage);
                }
            }
            diag.close();
        };
        diag.show();
    //}
}

//如果已经新增了6条推广收费配置数据，那么就不再允许新增新的推广收费配置（因为业务需求已发生变化，需要根据推广规则判断，所以该方法已作废）
function validateAdd() {
    var flag = true;//允许新增
    $.ajax({
        url : path + "/admin/promotionFeeConfig/validateAdd",
        type : "post",
        dataType : "json",
        async : false,
        success : function (data) {
            if (data.code == 400) {
                flag = false;//不允许新增
                top.hangge();
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + data.msg + "</span>",
                    buttons: {
                        ok: {
                            label: '我知道了'
                        }
                    }
                });
            }
        }
    });
    return flag;
}

//编辑
function edit(id, currentPage){
    top.jzts();
    var diag = new top.Dialog();
    diag.Drag = true;
    diag.Title ="编辑";
    diag.URL = path + '/admin/promotionFeeConfig/editPage?id=' + id;
    diag.Width = 1050;
    diag.Height = 580;
    diag.CancelEvent = function(){//关闭事件
        if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            if(currentPage == '0'){
                top.jzts();
                setTimeout("self.location=self.location",100);
            }else{
                nextPage(currentPage);
            }
        }
        diag.close();
    };
    diag.show();
}

//删除（逻辑删除）
function del(id, currentPage) {
    var flag = validateDelete(id);
    if (flag) {
        bootbox.confirm("确定要删除该条记录吗？删除后将无法恢复，可重新添加", function(result) {
            if(result) {
                top.jzts();
                var url = path +'/admin/promotionFeeConfig/delete?id=' + id;
                $.get(url, function(data) {
                    top.hangge();
                    bootbox.dialog({
                        message: "<span class='bigger-110'>" + data.msg + "</span>",
                        buttons: {
                            "button":{
                                "label":"确定",
                                "className":"btn-sm btn-success",
                                "callback": function() {
                                    nextPage(currentPage);
                                }
                            }
                        }
                    });
                });
            }
        });
    }
}

//如果只剩一个推广收费配置，那么不允许删除，要想删除该条数据必须再新增一条数据，因为至少要保留一条配置数据（根据推广规则）
function validateDelete(id) {
    var flag = true;//允许删除
    $.ajax({
        url : path + "/admin/promotionFeeConfig/validateDelete",
        type : "post",
        dataType : "json",
        async : false,
        data : {id : id},
        success : function (data) {
            if (data.code == 400) {
                flag = false;//不允许删除
                top.hangge();
                bootbox.dialog({
                    message: "<span class='bigger-110'>" + data.msg + "</span>",
                    buttons: {
                        "button" : {
                            "label" : "确定",
                            "className" : "btn-sm btn-success"
                        }
                    }
                });
            }
        }
    });
    return flag;
}
